#!/usr/bin/env node
const inquirer = require("inquirer");
const fs = require("fs");
const path = require("path");
const ejs = require("ejs");
const chalk = require("chalk");
const figlet = require("figlet");

console.log(
  chalk.yellow(figlet.textSync("z-cli", { horizontalLayout: "full" }))
);

inquirer
  .prompt([
    {
      type: "input",
      name: "name",
      message: "your project name?",
    },
  ])
  .then((answers) => {
    const tmpDir = path.join(__dirname, "templates");
    const desDir = process.cwd();

    fs.readdir(tmpDir, (err, files) => {
      if (err) throw err;
      files.forEach((item) => {
        // console.log(item)
        // 通过模板引擎渲染文件
        ejs.renderFile(path.join(tmpDir, item), answers, (err, result) => {
          // console.log(result)
          fs.writeFileSync(path.join(desDir, item), result);
        });
      });
    });
  });
